package cn.smbms.service.impl;

import cn.smbms.dao.user.UserMapper;
import cn.smbms.pojo.User;
import cn.smbms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;    //声明UserMapper接口引用


    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> findUsersWithConditions(User user) {
        try {
            return userMapper.getUserList(user);    //调用dao方法实现查询
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public boolean addNewUser(User user) {
        boolean result = false;
        try {
            if (userMapper.add(user) == 1){
                result = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return result;
    }
}
